home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13585 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  67 lines

  1. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
  2. From: grantp@usa.pipeline.com(Pete Grant)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Need help using g++ and Templates
  5. Date: 25 Mar 1996 23:04:24 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4j78po$foa@news1.h1.usa.pipeline.com>
  8. References: <4j7017$8m4@sal-sun133.usc.edu>
  9. NNTP-Posting-Host: 38.8.60.8
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete Grant)
  13. X-Newsreader: Pipeline v3.5.0
  14.  
  15. On Mar 25, 1996 12:34:47 in article <Need help using g++ and Templates>,
  16. 'radford@sal-sun133.usc.edu (Richard Radford)' wrote: 
  17.  
  18.  
  19. >I have created object files for the template class and the files that use 
  20.  
  21. >instances of the template class. When I compile using g++ version 2.7 I
  22. get  
  23. >errors saying I have a bunch of undefined symbols. The template i'm trying
  24. to  
  25. >use is for lists. All the undefined symbols are of the form List<Class I'm
  26.  
  27. >trying to create a list of>::member_function_of_template. Can anyone offer
  28. any  
  29. >advice on how to compile templates using g++. Any help would be greatly  
  30. >appreciated. Please respond by email. I have never posted to a news group 
  31.  
  32. >before and I'm not sure how I would retrieve any advice you may have for
  33. me. 
  34. >     
  35. >    Thanks in advance, Richard Radford     radford@nunki.usc.edu 
  36.  
  37. There are other ways, but the easiest is to place all your template 
  38. definitions into header file(s) and include the header(s) in all your 
  39. source modules that use those templates.  Something like: 
  40.  
  41. ////// file foo.h 
  42.  
  43. template<class T> 
  44. class Stack 
  45.  { 
  46.    public: 
  47.      Stack(int size = 0); 
  48.      T& pop(); 
  49.      void push(T&); 
  50.    .... 
  51.  }; 
  52.  
  53. template <class T> 
  54. Stack<T>::Stack(int siz) { ... body } 
  55.  
  56. template<class T> 
  57. T& Stack<T>::pop { return whatever...} 
  58.  
  59. I recommend that all template members for a class be placed 
  60. in a single header file.  Also, it might help maintenance 
  61. if each template class is in its own header. 
  62.  
  63. -- 
  64. Pete Grant 
  65. Kalevi, Inc. 
  66. Software Engineering & development
  67.